import request from '@/utils/request'
import type { DoctorListPage, DoctorParams, KnowledgeListPage, KnowledgeParams, TopDep, Image, ConsultOrderPreParams, ConsultOrderPreData, PartialConsult, ConsultPayParams, ConsultOrderItem, ConsultOrderListParams, ConsultOrderList } from '@/types/consult'
import type { Patient } from '@/types/user'

// 百科文章列表
export const getKnowledgePage = (params: KnowledgeParams) => request<KnowledgeListPage>('patient/home/knowledge', 'get', params)

// 关注医生列表
export const getDoctorList = (params: DoctorParams) => request<DoctorListPage>('home/page/doc', 'get', params)

// 关注
export const followApi = (id: string, type: 'topic' | 'knowledge' | 'doc' | 'disease') => request('like', 'post', { id, type })

// 获取科室数据
export const getAllDeps = () => request<TopDep[]>('dep/all')

// 患者图片上传
export const uploadImg = (file: File) => {
  // 组装成application/form-data格式的数据
  const formdata = new FormData()
  formdata.append('file', file)
  // 调上传接口
  return request<Image>('upload', 'post', formdata)
}

// 拉取预支付订单信息
export const getConsultOrderPre = (params: ConsultOrderPreParams) => request<ConsultOrderPreData>('patient/consult/order/pre', 'get', params)

// 获取患者详情数据
export const getPatientDetail = (id: string) => request<Patient>(`patient/info/${id}`)

// 创建极速问诊
export const createConsultOrder = (data: PartialConsult) => request<{ id: string }>('patient/consult/order', 'post', data)

// 获取支付地址
// export const getConsultOrderPayUrl = (data: ConsultPayParams) => request<{ payUrl: string }>('patient/consult/pay', 'post', data)
export const getConsultOrderPayUrl = (data: ConsultPayParams) => request<{ payUrl: string }>('patient/consult/mockPay', 'post', data)

// 获取问诊订单详情
export const getConsultOrderDetail = (orderId: string) => request<ConsultOrderItem>('patient/consult/order/detail', 'get', { orderId })

// 获取原始处方单(图片)
export const getPrescriptionPic = (id: string) => request<{ url: string }>(`patient/consult/prescription/${id}`)

// 评价医生
export const evaluateDocApi = (data: {
  docId: string
  orderId: string
  score: number
  content: string
  anonymousFlag: 0 | 1
}) => request<{ id: string }>('patient/order/evaluate', 'post', data)


// 用户的问诊订单列表记录
export const getConsultOrderList = (params: ConsultOrderListParams) => request<ConsultOrderList>('patient/consult/order/list', 'get', params)

// 取消订单
export const cancelOrder = (id: string) => request(`patient/order/cancel/${id}`,'put')

// 删除订单
export const delOrder = (id: string) => request(`patient/order/${id}`,'delete')